package com.mall.service.impl;

import com.mall.mapper.VipMapper;
import com.mall.po.Vip;
import com.mall.service.VipService;
import com.mall.util.ColumnEdit;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mahaoqi
 * @ClassName VipServiceImpl
 * @Description TODO
 * @Date 2021/1/5 20:07
 * @Version 1.0
 **/
@Service
public class VipServiceImpl implements VipService {

    @Resource
    private VipMapper vipMapper;
    @Resource
    private ColumnEdit columnEdit;

    /*
     * @Author mahaoqi
     * @Description 添加vip
     * @Date 2021/1/6 16:02
     * @Param [vip]
     * @return java.lang.Boolean
     **/
    @Override
    public Boolean addVip(Vip vip) {
        return vipMapper.insertOne(vip)>0;
    }

    /*
     * @Author mahaoqi
     * @Description 根据id删除
     * @Date 2021/1/6 17:22
     * @Param [vipid]
     * @return java.lang.Boolean
     **/
    @Override
    public Boolean removeById(int vipid) {
        return vipMapper.deleteById(vipid)>0;
    }

    /*
     * @Author mahaoqi
     * @Description 修改
     * @Date 2021/1/6 20:15
     * @Param [vip]
     * @return java.lang.Boolean
     **/
    @Override
    public Boolean modifyVip(Vip vip) {
        Vip findVip = vipMapper.selectById(vip.getVipid());
        if(findVip!=null){
            findVip = (Vip)columnEdit.updateObject(vip,findVip);
            return vipMapper.updateOne(findVip)>0;
        }
        return null;
    }

    /*
     * @Author mahaoqi
     * @Description 查找
     * @Date 2021/1/7 14:42
     * @Param [vipid]
     * @return com.mall.po.Vip
     **/
    @Override
    public Vip findById(Integer vipid) {
        return vipMapper.selectById(vipid);
    }

    /*
     * @Author mahaoqi
     * @Description 分页查询
     * @Date 2021/1/7 14:49
     * @Param [page, limit]
     * @return java.util.List<com.mall.po.Vip>
     **/
    @Override
    public List<Vip> findList(Integer page, Integer limit) {
        return vipMapper.selectList(page,limit);
    }

    /*
     * @Author mahaoqi
     * @Description 查询总记录条数
     * @Date 2021/1/7 15:12
     * @Param []
     * @return java.lang.Integer
     **/
    @Override
    public Integer findCount() {
        return vipMapper.selectCount();
    }

    /*
     * @Author mahaoqi
     * @Description 批量删除
     * @Date 2021/1/7 15:20
     * @Param [vipids]
     * @return boolean
     **/
    @Override
    public boolean removeBatch(Integer[] vipids) {
        return vipMapper.deleteBatch(vipids)>0;
    }


}
